﻿using System;
using System.Collections.Generic;
using System.Text;
using CeA.Reports.Atendimento.DataAccess.DTO;
using System.Data.OracleClient;
using System.Data;
using CeA.Reports.Atendimento.DataAccess.Helpers;
using CeA.Reports.Atendimento.DataAccess.Criteria;
using IBatisNet.DataMapper;

namespace CeA.Reports.Atendimento.DataAccess.DAO.Oracle {
    public class OracleDiaImpl : Dia {
        public OracleDiaImpl()                                          {
            //m_connection = OracleDAOFactory.CreateConnection();
        }


        /// <summary>
        /// Lista os Dias com critério de busca.
        /// </summary>
        /// <returns></returns>
        public List<DiaDTO> ListarIdentificacao(DiaCriteria criteria)   {
            IList<DiaDTO> list = Mapper.Instance()
                   .QueryForList<DiaDTO>("diaSelectList", criteria);
            return (List<DiaDTO>)list;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="criteria"></param>
        /// <returns></returns>
        public List<DiaPicoDTO> ListarDiaPico(DiaCriteria criteria)     {
            IList<DiaPicoDTO> list = Mapper.Instance()
                   .QueryForList<DiaPicoDTO>("FindAllDiaPico", criteria);
            return (List<DiaPicoDTO>)list;
        }


        /// <summary>
        /// Insere um novo Dia.
        /// </summary>
        /// <returns></returns>
        public DiaDTO Salvar(DiaDTO dia)                                {
            int diaKey = (int)Mapper.Instance().Insert("diaInsert", dia);
            dia.Id = diaKey;            
            return dia;
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="dia"></param>
        public void Atualizar(DiaDTO dia)                               {
            Mapper.Instance().Update("diaUpdate", dia);
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="dia"></param>
        public void AtualizarDiaPico(DiaPicoDTO dia)                    {
            if (dia.Id > 0)
                Mapper.Instance().Update("updateDiaPico", dia);
            else {
                Mapper.Instance().Update("updateDiaPicoYMD", dia);
                dia.Id = Mapper.Instance().QueryForObject<int>("getDiaIdBy", dia);
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        public void Excluir(int id)                                     {
            Mapper.Instance().Delete("diaDelete", id);
        }
    }
}
